package com.bing.bingPro.controller.zd;

import cn.hutool.core.lang.Assert;
import com.bing.bingPro.common.BaseResult;
import com.bing.bingPro.controller.dto.TZdIndexMonthDto;
import com.bing.bingPro.controller.vo.TZdIndexMonthVo;
import com.bing.bingPro.service.TZdIndexMonthService;
import com.bing.bingPro.util.ExcelData;
import com.bing.bingPro.util.WebExcelUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController
public class TZdIndexMonthController {

    @Resource
    private TZdIndexMonthService tZdIndexMonthService;

    @PostMapping("tZdIndexMonthList")
    public BaseResult<List<TZdIndexMonthVo>> tZdIndexMonthList(@RequestBody TZdIndexMonthDto tZdIndexMonthDto) {
        List<TZdIndexMonthVo> result = tZdIndexMonthService.tZdIndexMonthList(tZdIndexMonthDto);
        return new BaseResult<>(result);
    }


    @PostMapping("/tZdIndexMonthListExport")
    public void tZdIndexMonthListExport(HttpServletResponse response, @RequestBody TZdIndexMonthDto tZdIndexMonthDto) {
        try {
            Assert.notBlank(tZdIndexMonthDto.getTime(), "not time");
            //查询数据
            List<TZdIndexMonthVo> result = tZdIndexMonthService.tZdIndexMonthList(tZdIndexMonthDto);
            //整理查询的数据
            List<ExcelData> excelDataList = new ArrayList<>();
            ExcelData excelData = new ExcelData(TZdIndexMonthVo.class,
                    result);
            excelDataList.add(excelData);
            //写出到浏览器
            WebExcelUtil.download(response, "综调指标详表" + tZdIndexMonthDto.getTime(), excelDataList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/tZdIndexMonthListDateList")
    public BaseResult<List<String>> dateList() {
        return new BaseResult<>(this.tZdIndexMonthService.dateList());
    }
}
